import {resolve} from 'path';
import {defineConfig,loadEnv} from 'vite';
import vue from '@vitejs/plugin-vue2';

export default defineConfig(({mode}) => {
    const PROCESS_CONSTAINT = loadEnv(mode, process.cwd())
    const VITE_BASE_URL=PROCESS_CONSTAINT.VITE_BASE_URL
    console.log('>=====VITE_BASE_URL,',VITE_BASE_URL)

    return {
        server: {
            port: 89,
            // host:"localhost",
            proxy: {
                '/api1': {
                    target: 'http://localhost:9001/',
                    changeOrigin: true,
                    rewrite: (path) => path.replace(/^\/api1/, ''),
                },
                '/account': {
                    target: 'http://apidev.szqerp.com/',
                    changeOrigin: true,
                    //rewrite: (path) => path.replace(/^\/erp/, ''),
                },
                '/dictionary': {
                    target: 'http://apidev.szqerp.com/',
                    changeOrigin: true,
                    //rewrite: (path) => path.replace(/^\/erp/, ''),
                },
                '/erp': {
                    target: 'http://apidev.szqerp.com/',
                    changeOrigin: true,
                    //rewrite: (path) => path.replace(/^\/erp/, ''),
                },
                '/mes': {
                    target: 'http://apidev.szqerp.com/',
                    changeOrigin: true,
                    //rewrite: (path) => path.replace(/^\/erp/, ''),
                },
                '/api2': {
                    target: 'http://apidev.szqerp.com/',
                    changeOrigin: true,
                    rewrite: (path) => path.replace(/^\/api2/, ''),
                },
            },
        },
        base: '/code_generate/',
        resolve: {
            alias: {
                '@': '/src',
            },
            extensions: ['.js', '.jsx', '.ts', '.css', '.tsx', '.vue', '.json']
        },
        build: {
            target: 'esnext',
            minify: false,
            cssCodeSplit: true,
            rollupOptions: {
                input: {
                    table: './src/views/gCode/index.html',
                    tableField: './src/views/gCode/filed/index.html',
                    account: './src/views/account/index.html',
                    dic: './src/views/dic/index.html',
                    systemclass: './src/views/systemclass/index.html',
                    menus: './src/views/menus/index.html',
                },
            },
        },
        plugins: [
            vue(),
        ],
    }

});
